#include <stdlib.h>
#include <stdio.h>
#include "ui.h"
#include "op-basic.h"

void index_start()
{
    unsigned char selected;

    // Draw UI
    ui_cls();
    ui_add_empty_line(1);
    ui_add_border_line_text("Start");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("1: Basic operation");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("2: Number conversion");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("3: Arrangement & combination");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("4: General functions");
    ui_add_border_row_empty(2);
    ui_add_opt_desc("5: Back to calculator index");
    ui_add_border_row_empty(1);
    ui_add_border_line_single();
    ui_add_empty_line(1);
    printf("Please enter the operation number you want [1 ~ 5]: ");

    scanf("%d", &selected);
    switch (selected) {
        case 1:
            op_basic_init();
            break;
        case 2:
            op_conv_init();
            break;
        case 3:
            op_arrangement_init();
            break;
        case 4:
            op_general_init();
            break;
        case 5:
            index_init();
            break;
        default:
            ui_cls();
            printf("What you had selected is %d, which is incorrect.\n", selected);
            system("PAUSE");
            index_start();
    }
}

void index_init()
{
    unsigned char selected;

    // Draw UI
    ui_cls();
    ui_add_empty_line(1);
    ui_add_border_line_text("Calculator index");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("1: Start");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("2: Instruction");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("3: Exit");
    ui_add_border_row_empty(1);
    ui_add_border_line_single();
    ui_add_empty_line(1);
    printf("Please enter the operation number you want [1 ~ 3]: ");

    scanf("%d", &selected);
    switch (selected) {
        case 1:
            index_start();
            break;
        case 2:
            ui_cls();
            printf("Usage instruction: TO BE CONTINUED.\n");
            break;
        case 3:
            exit(0); // TODO
            break;
        default:
            ui_cls();
            printf("What you had selected is %d, which is incorrect.\n", selected);
            system("PAUSE");
            index_init();
    }
}
